package com.example.spareparts.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.example.spareparts.entity.BatchManagement;
import com.example.spareparts.service.BatchManagementService;
import java.util.List;

@RestController
@RequestMapping("/api/batchmanagement")
public class BatchManagementController {
    @Autowired
    private BatchManagementService batchManagementService;
    @GetMapping ("/listall")
    public List<BatchManagement> findAllBatchManagement(){
        return batchManagementService.findAllBatchManagement();
    }
    @PostMapping ("/insert")
    public void insertBatchManagement(@RequestBody BatchManagement batchManagement){
        batchManagementService.insertBatchManagement(batchManagement);
    }
    @PutMapping ("/update/{batchid}")
    public void updateBatchManagement(@PathVariable Long batchid, @RequestBody BatchManagement batchManagement){
        batchManagement.setBatchid(batchid);
        batchManagementService.updateBatchManagement(batchManagement);

    }
    @DeleteMapping ("/delete/{batchid}")
    public void deleteBatchManagement(@PathVariable Long batchid){
        batchManagementService.deleteBatchManagement(batchid);
    }
    @GetMapping ("/findbyid/{batchid}")
    public BatchManagement findBatchManagementById(@PathVariable Long batchid){
        return batchManagementService.findBatchManagementById(batchid);
    }
    @GetMapping ("/findbysparepartid/{sparepartid}")
    public List<BatchManagement> findBatchManagementBySparePartId(@PathVariable Long sparepartid){
        return batchManagementService.findBatchManagementBySparePartId(sparepartid);
    }
    @GetMapping ("/findbybatchnumber/{batchNumber}")
    public BatchManagement findBatchManagementByBatchNumber(@PathVariable String batchNumber){
        return batchManagementService.findBatchManagementByBatchNumber(batchNumber);
    }
}
